//
//  KAPickerView.swift
//  kano
//
//  Created by Sophia on 2024/8/14.
//

import BRPickerView

class KAPickerView: BRDatePickerView {
    
    var BLOCK_confirmBlock: ((NSDate, NSString) -> Void)?
    
    static func ka_showDatePicker(title: String, pickerMode: BRDatePickerMode, minDate: Date?, maxDate: Date?, selectDate: Date?, completion: @escaping (Date, String) -> Void) {
        let var_datePickerView = BRDatePickerView()
        var_datePickerView.calendar = Calendar(identifier: .gregorian)
        var_datePickerView.pickerMode = pickerMode
        var_datePickerView.title = title
        var_datePickerView.selectDate = (selectDate != nil) ? selectDate : Date()
        var_datePickerView.minDate = minDate
        var_datePickerView.maxDate = maxDate
        var_datePickerView.isAutoSelect = true
        var_datePickerView.resultBlock = { selectDate, selectValue in
            completion(selectDate!, selectValue!)
        }
        var_datePickerView.pickerStyle = ka_customStyle()

        var_datePickerView.show()
    }
    
    static func ka_showStringPicker(title: String, dataSources: [String]?, selectValue: String?, completion: @escaping (String) -> Void) {
        let var_stringPickerView = BRStringPickerView(pickerMode: .componentSingle)
        var_stringPickerView.title = title
        var_stringPickerView.dataSourceArr = dataSources
        var_stringPickerView.selectValue = selectValue
        var_stringPickerView.isAutoSelect = true
        var_stringPickerView.resultModelBlock = { resultModel in
            completion(resultModel!.value!)
        }
        var_stringPickerView.pickerStyle = ka_customStyle()
        
        var_stringPickerView.show()
    }
    
    static func ka_customStyle() -> BRPickerStyle {
        let var_customStyle = BRPickerStyle()
        var_customStyle.titleBarColor = .white
        var_customStyle.pickerColor = .white
        var_customStyle.pickerTextColor = .black
        var_customStyle.separatorColor = .color8A8891
        var_customStyle.titleTextColor = .black
        var_customStyle.titleTextFont = UIFont.systemFont(ofSize: 17)
        var_customStyle.cancelTextColor = .black
        var_customStyle.doneTextColor = .themeColor
        var_customStyle.selectRowTextFont = UIFont.boldSystemFont(ofSize: 18)
        var_customStyle.pickerHeight = 35.0
        var_customStyle.doneBtnTitle = "OK"
        var_customStyle.cancelBtnTitle = "Cancel"
        return var_customStyle
    }
}
